//
//  BSThemeCellModel.m
//  BaiSi
//
//  Created by Sycamore on 16/5/3.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "BSThemeCellModel.h"
#import "BSThemeItem.h"
#import "BSCommentItem.h"
#import "BSUserItem.h"
@implementation BSThemeCellModel

- (void)setItem:(BSThemeItem *)item
{
    _item = item;
    
    //计算topView的frame
    CGFloat margin = 10;
    CGFloat topX = 0;
    CGFloat topY = 0;
    CGFloat topW = BSScreenWidth;
    CGFloat textY = 70;
    CGFloat textW = topW - margin * 2;
    CGFloat textH = [item.text sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    _topViewFrame = CGRectMake(topX, topY, topW, textY + textH);
    
    _cellHeight = CGRectGetMaxY(_topViewFrame) + 10;
    
    //如果不是段子的时候，才会有pictureView
    if (item.type != ThemeTypeText && item.width) {
        CGFloat pictureX = 0;
        CGFloat pictureY = CGRectGetMaxY(_topViewFrame);
        CGFloat pictureW = BSScreenWidth;
        CGFloat pictureH = BSScreenWidth / item.width * item.height;
        
        if (pictureH > BSScreenHeight) {
            pictureH = 300;
            item.is_bigPicture = !item.is_gif;
        }
        
        _middleViewFrame = CGRectMake(pictureX, pictureY, pictureW, pictureH);
        _cellHeight = CGRectGetMaxY(_middleViewFrame);
    }
    
    //判断是否有最热评论
    if (item.top_cmt.count > 0) {
        CGFloat hotX = margin;
        CGFloat hotY = _cellHeight;
        CGFloat hotW = textW;
        CGFloat hotH = 21;
        
        //如果是文字评论
        if (item.commentItem.content.length > 0) {
            CGFloat textH = [item.commentItem.totleComment sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
            hotH = 21.5 + textH;
        }else{//如果是语音评论
            hotH =  42;
        }
        
        _hotCommentViewFrame = CGRectMake(hotX, hotY, hotW, hotH);
        _cellHeight = CGRectGetMaxY(_hotCommentViewFrame) + margin;
    }
    
    CGFloat bottomX = 0;
    CGFloat bottomY = _cellHeight ;
    CGFloat bottomW = BSScreenWidth;
    CGFloat bottomH = 40;
    
    _bottomViewFrame = CGRectMake(bottomX, bottomY, bottomW, bottomH);
    
    _cellHeight = CGRectGetMaxY(_bottomViewFrame) + margin;
    
}

@end
